home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-10-30 | 6.1 KB | 265 lines | [TEXT/EDIT] |
- ( ===== Extra Name Space Words ===== )
-
- ( This file defines words used to extend the Names space. This is used
- primarily for CONSTANT definitions for Macintosh symbols. This should
- not be used for variable definitions.)
-
- push.VOCAB.state
- ONLY FORTH
- ALSO DEVELOPMENT DEFINITIONS
- ALSO ASSEMBLER
-
- (
- |------------------------------------|
- | |
- --------- | --------- ---------- |
- | ptr | ---| | handle | <-- | handle | <--- |
- --------- ---------- | ----------
- | 0 | --- | ptr |
- ---------- ----------
- )
-
- 0 Module.list !
-
- ( Insert.Name.Space allocates an 8-byte array that holds three variables:
- The first variable is a handle to the inserted name space.
- The second variable is used as a forward linked list to point to the
- next handle. Used as follows:
-
- 4800 Insert.MODULE _FSEQU_
- )
-
- CODE get.A5
- MOVE.L A5,-(A6)
- RTS
- END-CODE MACH
-
- CODE find.Next ( lfa -- lfa vocab.id )
- MOVE.L (A6),A1 \ put current LFA in reg
- MOVE.L $40(A4),D3 \ CONTEXT
-
- @c
- TST.L D3
- BPL.S @start.looking
-
- @not.found
- MOVEQ.L #0,D0
- MOVE.L D0,(A6)
- MOVE.L D0,-(A6)
- RTS
-
- @start.looking
- MOVEA.L $-532(A5),A0 \ dictionary ptr
- MOVE.L D3,D2 \ copy CONTEXT
- ANDI.L #$F,D2 \ mask out for low dict
- ASL.L #$3,D2 \ multiply by 8
- ADDA.L $32(A0,D2.W),A0 \ get LAST for this vocab
- CMPI.B #$F,D3 \ does this dict vocab exist
- BEQ.S @not.found
-
- TST.L D3 \ have we run out of vocabs
- BEQ.S @look.this.vocab
-
- LSR.L #$4,D3 \ shift the next vocab
- BNE.S @check.LAST
-
- @look.this.vocab
- SUBQ.L #$1,D3
-
- @check.LAST
- CMP.L A0,A1 \ is the LAST in this vocab same as passed in
- BNE.S @e \ branch if not so
-
- MOVEQ.L #0,D0
- MOVEA.L D0,A0
- BEQ.S @we.found.it
-
- @e
- TST.L (A0) \ test lfa of word in vocab
- BEQ.S @c
-
- MOVE.L A0,D0 \ addr of lfa
- SUB.L (A0),D0 \ addr of previous word
- CMP.L A1,D0 \ is it equal to the word we are looking for
- BEQ.S @we.found.it
-
- SUBA.L (A0),A0 \ get next word
- BRA.S @e
-
- @we.found.it
- MOVE.L A0,(A6)
- MOVE.L D2,-(A6)
- RTS
- END-CODE
-
- : MODULE.VAR
- { | sfa -- }
- CREATE -4 ALLOT LAST link>seg -> sfa
- 1 sfa W!
- $41FA sfa 2+ W!
- 6 sfa 4+ W!
- $2D08 sfa 6 + W!
- $4E75 sfa 8 + W!
- 14 NP +!
- ;
-
- : Insert.MODULE
- { names.size | name.handle names.var -- result }
-
- names.size CALL NewHandle ( -- handle result )
- 0=
- IF
- ( allocation was successful )
- -> name.handle
- name.handle CALL MoveHHi DROP
- name.handle CALL HLock DROP
- ( store the pre-module NP in the module header )
- NP @ name.handle @ !
- ( set NP to point to 8 bytes into the module )
- name.handle @ CALL StripAddress 8 + NP !
-
- MODULE.VAR ( now the new names record is defined )
- ( get the address of the module record )
- LAST LINK>BODY EXECUTE -> names.var
- name.handle names.var ! ( store the handle )
-
- ( now link to the list )
- Module.list @ 0=
- IF
- names.var Module.list !
- 0 names.var 4+ !
- ELSE
- ( link to the tail of the list )
- Module.list @ ( get ptr to end )
- names.var Module.list ! ( end now is names.var )
- names.var 4 + ! ( names.var points to previous end )
- THEN
- ELSE
- DROP ( the handle )
- -1 ABORT" ABORT - Memory Allocation failed for inserted Name Space."
- THEN
- ;
-
- : restore.Name.Space
- ( Used in the form: _SYSEQU_ restore.Name.Space
- where _SYSEQU_ was a name created by Insert.Name.Space. )
-
- ( store the lfa of the LAST word in this module in the module header )
- DUP
- LAST SWAP @ @ 4+ ! ( store the last lfa in the module )
- @ ( the handle from the module record )
- @ ( the pointer from the handle )
- @ ( the original NP from the name module )
- NP !
- ;
-
- : forget.MODULE
- ( used in the form: _SYSEQU_ forget.MODULE )
- { module.var | module.var.lfa next.lfa vocab.ID -- }
-
- module.var @ @ CALL StripAddress
- 8 + -> module.var.lfa
-
- ( get the lfa of the last word in the module )
- module.var.lfa 4- @ -> next.lfa
-
- next.lfa find.NEXT -> vocab.ID -> next.lfa
- next.lfa
- IF
- next.lfa ( addr of 1st lfa after module )
- module.var.lfa DUP @ - ( addr of 1st lfa before module )
- - ( create offset )
- next.lfa ! ( store in post-module lfa )
-
- ELSE
- ( the lfa is zero, so the last word defined in this
- vocabulary is the last word of the module )
- module.var.lfa DUP @ - ( addr of 1st lfa before module )
- MOVE.L $-532(A5),-(A6) \ dict ptr
- - ( create offset from start of dict )
-
- ( store this offset in the LAST variable for this vocabulary )
- vocab.ID
- MOVE.L $-532(A5),A0 \ TEXT1 ptr
- MOVE.L (A6)+,D2 \ partial offset to LAST for this vocab
- LEA $32(A0,D2.W),A0 \ get addr of LAST for this vocab
- MOVE.L (A6)+,(A0) \ store the new LAST for this vocab
-
- ( also update LAST and NP if needed )
- LAST module.var.lfa 4- @ =
- IF
- module.var.lfa DUP @ - ( addr of 1st lfa before module )
- MOVE.L (A6)+,$-1E0(A5) ( update LAST )
- module.var.lfa 8 - @ NP ! ( update NP to original setting )
- THEN
- THEN
-
- ( now we have to remove this module from the module linked list )
- Module.list @ module.var =
- IF
- ( the module is the tail )
- module.var 4+ @ Module.list !
- ELSE
- ( the module is either the middle or head )
- Module.list @ ( get the pointer to the last )
- BEGIN
- DUP 4+ @ module.var = NOT ( -- next.ptr flag )
- WHILE
- 4+ @
- REPEAT
- ( -- next.ptr )
- module.var 4+ @ ( -- next.ptr prev.ptr )
- SWAP 4+ !
- THEN
-
- module.var @ CALL HUnlock DROP
- module.var @ CALL DisposHandle DROP
- HASHFORGET
- ;
-
- ( We need to redefine EMPTY so the handles can be de-allocated.)
-
- push.VOCAB.state
- ONLY MAC
- ALSO ASSEMBLER
- ALSO FORTH DEFINITIONS
- ALSO DEVELOPMENT
-
- CODE EMPTY
- MOVEQ.L #0,D3
- MOVE.L Module.list,D0 \ get pointer to namelist tail
- BEQ.S @normal
-
- @del.handle
- MOVEA.L D0,A1 \ get address of tail
- MOVE.L (A1),-(A6) \ put handle on stack
- ADDQ.L #1,D3 \ increment handle counter
- MOVE.L 4(A1),D0 \ get pointer to next record in list
- BEQ.S @normal
- BRA.S @del.handle
-
- @normal
- MOVE.L D3,-(A6)
- JSR EMPTY
-
- \ now deallocate the handles, if any
- MOVE.L (A6)+,D3
-
- @dealloc.loop
- DBRA D3,@dealloc
- BRA.S @myexit
-
- @dealloc
- MOVE.L (A6)+,A0
- _HUnlock
- _DisposHandle
- BRA.S @dealloc.loop
-
- @myexit
- RTS
- END-CODE
-
- pop.VOCAB.state
-
- pop.VOCAB.state
-